<script setup lang='ts'>
  import { nextTick, reactive, ref } from 'vue';
  import { auditApi } from '@/api/controller';
  import { ToastSuccess, Toastloading } from '@/utils/public';
import { getHMMSS } from '@/utils';
  const formLabelWidth = '120px'
  const dataForm = ref()
  const $emit = defineEmits(['updateList'])
  const action = reactive({
    dialogFormVisible:false,
    disabled:false,
    title:'',
    update_time:'',
  })
  interface formQuert {
    id:number
    note:string
  }
  let form = reactive({} as formQuert)
  const formRules = {
    note: [{ required: true, message: "请输入处理说明", trigger: "blur" }],
  }
  const handleSubmit = ()=>{
    dataForm.value.validate(async(valid:any)=>{
      if(!valid) return
      const loading = Toastloading()
      await auditApi.changestatus(form).then(()=>{
        ToastSuccess('处理成功')
        loading.close()
        $emit('updateList')
        closeDialog()
      }).catch(()=>{
        loading.close()
      })
    })
  }
  const openDialog = (query:any={})=> {
    const { id=0, note='', fe_status=0, update_time=0} = query
    action.disabled = fe_status?true:false
    action.update_time = update_time>0?getHMMSS(update_time * 1000):''
    Object.assign(form,{
      id, note
    })
    action.dialogFormVisible = true
  }
  const closeDialog = ()=>{
    form = reactive({} as formQuert)
    nextTick(() => {
      dataForm.value.clearValidate();
    });
    action.dialogFormVisible = false
  }
  defineExpose({
    openDialog
  })
</script>

<template>
  <div>
    <el-dialog
      top="10vh"
      class="xm-dialog input-width"
      v-model="action.dialogFormVisible"
      :close-on-click-modal="action.disabled"
      :show-close="action.disabled"
      :close-on-press-escape="action.disabled"
      width="52%"
      title="处理说明">
      <el-form ref="dataForm" :model="form" :rules="formRules">
        <el-form-item :label-width="formLabelWidth" label="处理说明" prop="note" >
          <el-input
            v-model="form.note"
            :autosize="{ minRows: 6, maxRows: 6}"
            type="textarea"
            placeholder="请输入处理说明"
          />
          <span v-if="action.update_time" >处理时间：{{ action.update_time }}</span>
        </el-form-item>
      </el-form>
      <template v-if="!action.disabled" #footer>
        <span class="dialog-footer">
          <el-button @click="closeDialog">取 消</el-button>
          <el-button type="primary" @click="handleSubmit">确 定</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>